<?php
namespace app\admin\controller;

use support\Controller;
use support\Request;
use bang\jwt\Jwt;

class Index extends Controller
{
    public function test()
    {
        $expireTime = 60 * 60 * 24 * 2;
        $data = [
            'user_id' => 199,
            'expire' => $expireTime
        ];

        // 最终生成的token
        $token = $this->createToken( $data , time() + $expireTime );
        echo $token;
        //解密token
        $decodeData = $this->decodeToken($token);
    }

    public function index(Request $request)
    {
        return response('hello easyman');
    }

    public function view(Request $request)
    {
        return view('index/view', ['name' => 'webman']);
    }

    public function json(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);
    }

    public function file(Request $request)
    {
        $file = $request->file('upload');
        if ($file && $file->isValid()) {
            $file->move(public_path().'/files/myfile.'.$file->getUploadExtension());
            return json(['code' => 0, 'msg' => 'upload success']);
        }
        return json(['code' => 1, 'msg' => 'file not found']);
    }
    
}
